from flask import Blueprint,jsonify,request
from db import db1
import json

users_bp = Blueprint('users',__name__)

@users_bp.route('/show')
def show():
    sql = 'select * from hahah'
    res = db1.fid_all(sql)
    return jsonify({"code":200,"list":res})

@users_bp.route('/yewu',methods=['POST','GET','PUT','DELETE'])
def yewu():
    if request.method == 'POST':
        data = request.data
        if data:
            data = json.loads(data)
        else:
            data = request.form
        sql = '''insert into yewu values(0,'%s','%s') '''%(data['name'],'')
        db1.update(sql)
        return jsonify({"code":200})

    elif request.method == 'GET':
        sql = '''select * from yewu'''
        res = db1.fid_all(sql)
        return jsonify({"code":200,"list":res})


